package com.xingxing.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.xingxing.Activity.R;
import com.xingxing.Bean.Likes;

import java.util.ArrayList;

public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MyViewHolder> {
    ArrayList<Likes> likes;
    private Context mContext;

    public MessageAdapter(Context context,String json) {
        mContext = context;
        likes = new Gson().fromJson(json, new TypeToken<ArrayList<Likes>>() {
        }.getType());
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.recycler_item_message, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.name.setText(likes.get(position).getUserAccount());
    }

    @Override
    public int getItemCount() {
        return likes.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView name;

        public MyViewHolder(View view) {
            super(view);
            name = (TextView) view.findViewById(R.id.et_nickName);
        }
    }
}